
source("shannon_entropy.R")

complexity = function(probs,entropy){
  p = which(probs > 1e-30)
  N = length(probs[p])  
  P_e = rep(1/N, N)  
  J = shannon_entropy( (probs[p] + P_e) / 2  ) - shannon_entropy(probs[p])/2 - shannon_entropy(P_e)/2
  aux = (   ((N+1)/N) * log(N + 1) - 2*log(2*N) + log(N)    )
  Q_0 = -2*(1/aux)
  Q = Q_0 * J
  complexity = Q*entropy
  return(complexity)
}







